package com.example.costumview.activity2;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.costumview.R;
import com.example.costumview.customview2.HorizontalScrollViewEx;
import com.example.costumview.customview2.HorizontalScrollViewEx2;
import com.example.costumview.customview2.ListViewEx2;

import java.util.ArrayList;

public class ViewConflict2Activity extends AppCompatActivity {
    private HorizontalScrollViewEx2 mListContainer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_conflict2);
        initView();
    }
    private void initView() {
        LayoutInflater inflater = getLayoutInflater();
        mListContainer = findViewById(R.id.container2);

        Display defaultDisplay = getWindowManager().getDefaultDisplay();
        Point point = new Point();
        defaultDisplay.getSize(point);

        int screenWidth = point.x;
        int screenHeight = point.y;

        for (int i = 0; i < 3; i++) {
            ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.listview_page2, mListContainer, false);
            layout.getLayoutParams().width=screenWidth;
            TextView textView=layout.findViewById(R.id.title2);
            textView.setText("page "+(i+1));
            layout.setBackgroundColor(Color.rgb(255/(i+1),0,255/(i+1)));

            createList(layout);
            mListContainer.addView(layout);
        }

    }

    private void createList(ViewGroup layout) {
        ListViewEx2 listView2=layout.findViewById(R.id.list2);
        listView2.setHorizontalScrollViewEx2(mListContainer);
        ArrayList<String> datas=new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            datas.add("name:"+i);
        }
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.item_listview,R.id.name,datas);
        listView2.setAdapter(adapter);
    }

}